<?php

namespace app\api\model;

use fast\Http;
use think\Model;

class Upgrade extends Model
{
// 定义大等级和小等级的数量
    private $maxMajorLevels = 9; // 例如：士兵、士官、将领
    private $maxMinorLevels = 9; // 每个大等级下的小等级数量

    // 初始化订单数数组
    private $levelList = [];

    public function __construct()
    {
        parent::__construct();

        // 计算每个小等级所需的订单数
        for ($major = 1; $major <= $this->maxMajorLevels; $major++) {
            for ($minor = 1; $minor <= $this->maxMinorLevels; $minor++) {
                //dump($major);
                //dump(($major - 1) * 10 + $minor * 10);
                $vaule = 1;
                if ($major==2){
                    $vaule = $major+8;
                } elseif ($major==3){
                    $vaule = $major+16;
                } elseif ($major==4){
                    $vaule = $major+24;
                } elseif ($major==5){
                    $vaule = $major+32;
                } elseif ($major==6){
                    $vaule = $major+40;
                } elseif ($major==7){
                    $vaule = $major+48;
                } elseif ($major==8){
                    $vaule = $major+56;
                } elseif ($major==9){
                    $vaule = $major+64;
                }
                $this->levelList["$major"]["$minor"] = $vaule * 10 + ($minor-2) * 10;
            }
        }


    }

    // 获取当前等级
    public function getCurrentLevel($userOrders)
    {
        foreach ($this->levelList as $k=>$v){
            foreach ($v as $kk=>$vv){
                if ($userOrders<$vv){
                    if ($kk-1==0){
                        $k = $k-1;
                        $kk = 9;
                    } else {
                        $kk = $kk-1;
                    }
                    return [
                        'major' => $k,
                        'minor' => $kk,
                        'orderCount' => $this->levelList[$k][$kk]
                    ];
                } elseif($userOrders==$vv) {
                    return [
                        'major' => $k,
                        'minor' => $kk,
                        'orderCount' => $this->levelList[$k][$kk]
                    ];
                }
            }
        }
        return null;
    }

}